<template>
	<view class="guangz">
		<view class="biaqishijian">
			<view class="biqo">
				已添加关注标签
			</view>
			<!-- <view class="bianjia" @click="chuxi">
				<view class="bianjw">
					编辑
				</view>
				<view class="bianjimg">
					<image src="../../static/3328.png" mode=""></image>
				</view>
			</view> -->
			<view class="bianjia" @click="this.showa= true">
				<view class="bianjw">
					编辑
				</view>
				<view class="bianjimg">
					<image src="../../static/3328.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="neir">
			<view class="neiry" v-for="(item , index) in ibiao" :key="index">
				{{ getText(item) }}
				<image src="../../static/jh.png" mode="" v-show="show"></image>
			</view>
		</view>
		<view class="jiaojiao" v-show="show">
			确认修改
		</view>
	</view>
	<u-popup :show="showa" mode="bottom" @close="close" @open="open">
		<view>
			<view class="neir">
				<view class="neiry" v-for="(item, index) in biao" :key="index"
					:class="{ selected: selectedIndexes.includes(index) }" @click="toggleSelection(index)">
					{{ item.title }}
				</view>

			</view>
			<view class="jiaojiao" @click="submitSelection">
				确认修改
			</view>
		</view>
	</u-popup>
</template>

<script>
	import {
		memberTags,
		modifyMemberInfo,
		imemberTags
	} from "../../request/api.js"
	export default {
		data() {
			return {

				show: false,
				showa: false,
				biao: [],
				ibiao: [],
				selectedIndexes: []

			}
		},
		onLoad() {

		},
		onShow() {
			this.biaoq()
			this.ibiaoq()
			console.log(JSON.parse(uni.getStorageSync('userInfo')), '是否登录');
			if (uni.getStorageSync('userInfo')) {
				this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
			}
		},
		methods: {
			getText(item) {
				if (item == 1) {
					return '家政';
				} else if (item == 2) {
					return '小时工';
				} else if (item == 3) {
					return '保洁';
				} else if (item == 4) {
					return '广告';
				} else if (item == 5) {
					return '代办';
				} else {
					return '招聘';
				}
			},
			toggleSelection(index) {
				if (this.selectedIndexes.includes(index)) {
					const selectedIndex = this.selectedIndexes.indexOf(index);
					this.selectedIndexes.splice(selectedIndex, 1);
				} else {
					this.selectedIndexes.push(index);
				}
			},

			submitSelection() {
				const selectedItems = this.selectedIndexes.map(index => this.biao[index].value).join(',')
				//修改

				modifyMemberInfo({
					tag: selectedItems
				}).then(rea => {
					this.showa = false
					this.ibiaoq()
				})
			},


			//获取内容
			biaoq() {
				// console.log(lll);
				memberTags().then(res => {
					console.log(res.result);
					this.biao = res.result
				})
			},
			//获取用户标签
			ibiaoq() {
				// console.log(lll);
				imemberTags().then(reb => {
					console.log(reb);
					this.ibiao = reb.result
				})
			},

			chuxi() {
				this.show = !this.show
			},
			open() {
				// console.log('open');
			},
			close() {
				this.showa = false
				// console.log('close');
			}
		}
	}
</script>

<style scoped lang="less">
	.selected {
		color: red;
	}

	.guangz {
		height: 100vh;
		background: #FAFAFA;
	}

	.biaqishijian {
		width: 702rpx;
		display: flex;
		margin: 0 auto;
		padding-top: 50rpx;
		box-sizing: border-box;

		.biqo {
			 
			font-weight: 400;
			font-size: 26rpx;
			color: #333333;
			font-style: normal;
			text-transform: none;
		}

		.bianjia {
			display: flex;
			margin: 0 50rpx;

			.bianjw {
				 
				font-weight: 400;
				font-size: 28rpx;
				color: #F8492E;
				font-style: normal;
				text-transform: none;
				margin-right: 10rpx;
			}

			.bianjimg {
				width: 22rpx;
				height: 26rpx;

				image {
					width: 22rpx;
					height: 26rpx;
				}
			}
		}

		.bianji {
			display: flex;

			.bianjw {
				 
				font-weight: 400;
				font-size: 28rpx;
				color: #F8492E;
				font-style: normal;
				text-transform: none;
				margin-right: 10rpx;
			}

			.bianjimg {
				width: 26rpx;
				height: 26rpx;

				image {
					width: 26rpx;
					height: 26rpx;
				}
			}
		}
	}

	.neir {
		width: 702rpx;
		margin: 0 auto;
		box-sizing: border-box;
		background: #FFFFFF;
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
		border-radius: 13rpx 13rpx 13rpx 13rpx;
		padding-top: 20rpx;

		.neiry {
			width: fit-content;
			padding: 16rpx 36rpx;
			box-sizing: border-box;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			border: 1rpx solid #CCCCCC;
			position: relative;
			margin-bottom: 20rpx;
			margin-left: 15rpx;
			margin-right: 15rpx;

			image {
				width: 36rpx;
				height: 36rpx;
				position: absolute;
				right: -12rpx;
				top: -12rpx;
			}
		}
	}

	.queding {}

	.jiaojiao {
		margin: 0 auto;
		width: 702rpx;
		height: 88rpx;
		background: #F8492E;
		border-radius: 50rpx 50rpx 50rpx 50rpx;
		 
		font-weight: 500;
		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		font-style: normal;
		text-transform: none;
		margin-top: 200rpx;
	}
</style>